package com.tide.crm.comm;

import com.tide.crm.dto.LoginUser;
import com.tide.crm.service.TokenService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;

public class BaseController {

    private static final String TOKEN_KEY = "token";

    @Autowired
    private TokenService tokenService;

    public LoginUser getUserInfoByToken(HttpServletRequest request){
        String token = request.getParameter(TOKEN_KEY);
        if (StringUtils.isBlank(token)) {
            token = request.getHeader(TOKEN_KEY);
        }
        LoginUser loginUser = tokenService.getLoginUser(token);
        return loginUser;
    }
}
